/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ManageBLL;

import ManageDAL.DALManufacture;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;

/**
 *
 * @author Pham
 */
public class BLLManufacture {
    //attributes
    int manufatureID;
    String manufactureName;
    DALManufacture dalManu;

    public int getManufatureID() {
        return manufatureID;
    }

    public void setManufatureID(int manufatureID) {
        this.manufatureID = manufatureID;
    }

    public String getManufactureName() {
        return manufactureName;
    }

    public void setManufactureName(String manufactureName) {
        this.manufactureName = manufactureName;
    }
    
    
    //constructors
    public BLLManufacture()
    {
        dalManu = new DALManufacture();
    }
    public BLLManufacture(ResultSet rs) throws SQLException
    {
        try{
            this.manufatureID = rs.getInt("manufacture_id");
            this.manufactureName = rs.getString("manufacture_name");
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
    }
    
    //method get comboboxmodel
    public DefaultComboBoxModel getComboboxModelManu()
    {
        try{
            DefaultComboBoxModel cbModel = new DefaultComboBoxModel();
            //cbModel.addElement("Tất cả các hãng...");
            for(BLLManufacture itemManu : dalManu.getListManu()){
                cbModel.addElement(itemManu.getManufactureName());
            }
            return cbModel;
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e.getMessage());
            return null;
        }
    }
    
    //method get Manufacture by name
    public BLLManufacture getManuIDbyName(String ManuName)
    {
        try
        {
            
            for(BLLManufacture itemManu : dalManu.getListManu())
            {
                if(ManuName.equals(itemManu.getManufactureName()))
                {
                    return itemManu;
                }
            }
            return null;
        }
        catch(Exception ex)
        {
            System.err.print(ex.getMessage());
            return null;
        }
    }
    
    
}
